/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.plechinger.mcremote.server.craft;

import java.io.Serializable;
import java.util.Date;

/**
 *
 * @author Lukas
 */
public class CraftLogElement implements Serializable{
    
    private static long serialVersionUID = 1L;

    public enum Type {

        TEXT, INFO, WARNING, ERROR;
    }
    private Type type;
    private String message;
    private Date date;

    public CraftLogElement(String logtext) {

        if (logtext.contains("[INFO]")) {
            type = Type.INFO;
            message = subLog(logtext);
        } else if (logtext.contains("[WARNING]")) {
            type = Type.WARNING;
            message = subLog(logtext);
        } else if (logtext.contains("[ERROR]")) {
            type = Type.ERROR;
            message = subLog(logtext);
        } else {
            type = Type.TEXT;
            message = logtext;
        }
        
        date=new Date();
    }

    private String subLog(String log) {
        return log.substring(log.indexOf("] ") + 2);
    }

    public String getMessage() {
        return message;
    }

    public Type getType() {
        return type;
    }

    public Date getDate() {
        return date;
    }

    @Override
    public String toString() {
        return "LogElement{" + "type=" + type + ", message=" + message + '}';
    }
    
}
